package com.feng.leetcode;

public class Fourtenth {
    public static void main(String[] args) {
        System.out.println(longestCommonPrefix(new String[]{"a"}));
    }

    public static String longestCommonPrefix(String[] strs) {
        if (strs.length == 0){
            return "";
        }
        String ans = "";
        for (int i = 0; i <= strs[0].length(); i++) {
            ans = strs[0].substring(0,i);
            boolean flag = true;
            for (int j = 1; j < strs.length; j++) {
                if (!strs[j].startsWith(ans)){
                    flag = false;
                }
            }
            if (!flag){
                if (ans.length() == 1){
                    return "";
                }else {
                    return ans.substring(0,ans.length()-1);
                }
            }
        }
        return ans;
    }
}
